package org.gienah.harness.artifacts;

import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionException;
import org.springframework.transaction.TransactionStatus;

/**
 * @author Santiago L. Valdarrama
 */
public class MockPlatformTransactionManager
		implements PlatformTransactionManager {

	private int createdTransactions;
	private int openTransactions;
	
	
	public void initialize() {
		this.createdTransactions = 0;
		this.openTransactions = 0;
	}

	public void commit(final TransactionStatus status)
			throws TransactionException {

	}

	public void rollback(final TransactionStatus status)
			throws TransactionException {

		this.openTransactions--;
	}

	public TransactionStatus getTransaction(final TransactionDefinition definition)
			throws TransactionException {

		this.createdTransactions++;
		this.openTransactions++;
		return new MockTransactionStatus();
	}

	public int getCreatedTransactions() {
		return this.createdTransactions;
	}

	public int getOpenTransactions() {
		return this.openTransactions;
	}

}
